package com.beauty.common.xml;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.SAXException;

public class SaxService {

	public static List<HashMap<String, String>> readXML(
			InputStream inputStream, String nodeName) {
		SAXParserFactory spf = SAXParserFactory.newInstance();
		List<HashMap<String, String>> list = null;
		try {
			SAXParser parser = spf.newSAXParser();
			MyHandler handler = new MyHandler(nodeName);
			parser.parse(inputStream, handler);
			list = handler.getList();
		} catch (ParserConfigurationException e) {
			e.printStackTrace();
		} catch (SAXException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (null != inputStream) {
				try {
					inputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return list;
	}
}
